package com.zzyl.controller;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusResponseBody;
import com.aliyun.iot20180120.models.QueryThingModelPublishedResponseBody;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.dto.MemberDto;
import com.zzyl.service.IotService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.MemberVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @className: IotController
 * @description:
 * @author: InnovatorX
 * @date: 2024/6/8 9:31
 * @Version: 1.0
 */
@RestController
@Slf4j
@Api(tags = "物联网接口")
@RequestMapping("/iot")
public class IotController extends BaseController {
    @Autowired
    private IotService iotService;

    /**
     * 同步产品列表
     *
     * @return
     */
    @PostMapping("/syncProductList")
    @ApiOperation("同步产品列表")
    public ResponseResult syncProductList() {
        iotService.syncProductList();
        return success();
    }

    @GetMapping("/allProduct")
    @ApiOperation("获取所有产品列表")
    public ResponseResult<List<ProductVo>> allProduct() {
        List<ProductVo> productVos = iotService.allProduct();
        return success(productVos);
    }

    @PostMapping("/RegisterDevice")
    @ApiOperation("注册设备")
    public ResponseResult registerDevice(@RequestBody DeviceDto dto) {
        iotService.registerDevice(dto);
        return success();
    }

    /**
     * 分页查询设备列表
     *
     * @param dto
     * @return
     */
    @GetMapping("/pageQueryDevice")
    @ApiOperation("分页查询设备列表")
    public ResponseResult<PageResponse<DeviceVo>> pageQueryDevice(DevicePageQueryDto dto) {
        PageResponse<DeviceVo> deviceDtos = iotService.findByPage(dto);
        return success(deviceDtos);
    }

    @PostMapping("/QueryDeviceDetail")
    @ApiOperation("查询设备详情")
    public ResponseResult<DeviceVo> QueryDeviceDetail(@RequestBody DeviceDto dto) {
        DeviceVo deviceVo = iotService.findDeviceDetail(dto);
        return success(deviceVo);
    }

    /**
     * 查看指定产品的已发布物模型中的功能定义详情
     * @param dto
     * @return
     */
    @PostMapping("/QueryThingModelPublished")
    @ApiOperation("查看指定产品的已发布物模型中的功能定义详情")
    public ResponseResult<QueryThingModelPublishedResponseBody.QueryThingModelPublishedResponseBodyData> QueryThingModelPublished(@RequestBody DeviceDto dto) {
        QueryThingModelPublishedResponseBody.QueryThingModelPublishedResponseBodyData productVos = iotService.QueryThingModelPublished(dto);
        return success(productVos);
    }
}
